package celcatSynchronizer.ui;

import com.google.gdata.data.calendar.CalendarEntry;
import java.awt.Component;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.ListCellRenderer;
import javax.swing.UIManager;

/**
 * Renderer des calendriers Google.
 */
public class ListCellRendererCalendar extends JLabel implements ListCellRenderer
{
	/**
	 * Constructeur.
	 */
	public ListCellRendererCalendar()
	{
		setOpaque(true);
	}
	
	@Override
	public Component getListCellRendererComponent(JList p_list, Object p_value, int p_index, boolean p_isSelected, boolean p_cellHasFocus)
	{
		if(p_value == null || p_value.getClass() != CalendarEntry.class)
			return this;
		
		if(p_isSelected)
		{
			setBackground(UIManager.getColor("List.selectionBackground"));
			setForeground(UIManager.getColor("List.selectionForeground"));
		}
		else
		{
			setBackground(UIManager.getColor("List.background"));
			setForeground(UIManager.getColor("List.foreground"));
		}
		
		setText(((CalendarEntry)p_value).getTitle().getPlainText());
		
		return this;
	}
}
